set(SHARED_TARGET tensorrt_plugin)
set(TARGET_DIR ${CMAKE_CURRENT_SOURCE_DIR})

set(PLUGIN_SOURCES)
set(PLUGIN_CU_SOURCES)

add_definitions(-DTV_CUDA)
set(CMAKE_CXX_FLAGS "-O3")

set(PLUGIN_LISTS common
  SxaiPlugin
)

foreach(PLUGIN_ITER ${PLUGIN_LISTS})
  include_directories(${PLUGIN_ITER})
  add_subdirectory(${PLUGIN_ITER})
endforeach(PLUGIN_ITER)

list(APPEND PLUGIN_SOURCES plugins.cpp)

list(APPEND PLUGIN_SOURCES "${PLUGIN_CU_SOURCES}")

# set(CUDA_SEPARABLE_COMPILATION ON)
# set(CUDA_PROPAGATE_HOST_FLAGS OFF)

# ################### SHARED LIBRARY ###############

add_library(${SHARED_TARGET} SHARED ${PLUGIN_SOURCES})

target_include_directories(
  ${SHARED_TARGET}
#  PUBLIC ${PROJECT_SOURCE_DIR}/include
#  PUBLIC ${CUB_ROOT_DIR}
  PRIVATE ${PROJECT_SOURCE_DIR}/common
#  PUBLIC ${CUDA_INSTALL_DIR}/include
  PRIVATE ${TARGET_DIR})
  
set_target_properties(
  ${SHARED_TARGET}
  PROPERTIES CXX_STANDARD "17"
             CXX_STANDARD_REQUIRED "YES"
             CXX_EXTENSIONS "NO"
             ARCHIVE_OUTPUT_DIRECTORY "${TRT_OUT_DIR}"
             LIBRARY_OUTPUT_DIRECTORY "${TRT_OUT_DIR}"
             RUNTIME_OUTPUT_DIRECTORY "${TRT_OUT_DIR}")

set_target_properties(${SHARED_TARGET} PROPERTIES VERSION ${TRT_VERSION}
                                                  SOVERSION ${TRT_SOVERSION})

set_target_properties(${SHARED_TARGET} PROPERTIES PUBLIC_HEADER "plugins.h")

set_property(TARGET ${SHARED_TARGET} PROPERTY CUDA_STANDARD 14)
set_property(TARGET ${SHARED_TARGET} PROPERTY CUDA_ARCHITECTURES ${GPU_ARCHS})

message(STATUS "CUBLAS_LIB=${CUBLAS_LIB}")
target_link_libraries(
  ${SHARED_TARGET}
  ${CUBLAS_LIB}
  ${CUBLASLT_LIB}
  ${CUDART_LIB}
  ${CUDNN_LIB}
  nvinfer
  ${CMAKE_DL_LIBS}
)

message("cudart_lib : ${CUDART_LIB}")

# ################################## INSTALLATION
# ##############################################################################

install(
  TARGETS ${SHARED_TARGET}
  RUNTIME DESTINATION ${PROJECT_NAME}/bin
  LIBRARY DESTINATION ${PROJECT_NAME}/lib
  ARCHIVE DESTINATION ${PROJECT_NAME}/lib
  PUBLIC_HEADER DESTINATION ${PROJECT_NAME}/include/${PROJECT_NAME}
  )
